<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        position: absolute;
        left: 0;
        top: 0;
        width: 100px;
        height: 100px;
        background-color: pink;
        /* border: 1px solid #000; */
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <script>
      var div = document.querySelector(".box");
      var timerId = setInterval(function () {
        var currentPosition = div.offsetLeft;
        var step = 10; // 步长值
        if (currentPosition < 800) {
          currentPosition += step;
          div.style.left = currentPosition + "px";
        } else {
          clearInterval(timerId);
        }
      }, 15);
    </script>
  </body>
</html>
